package com.hulk.ratel.manage.commoncache;

import com.alicp.jetcache.anno.CacheType;
import com.alicp.jetcache.anno.Cached;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.hulk.ratel.common.constant.enums.PayOrgStatus;
import com.hulk.ratel.common.constant.enums.YesOrNo;
import com.hulk.ratel.persistence.entity.PayorgInfo;
import com.hulk.ratel.persistence.repository.IPayorgInfoRepository;

import com.hulk.ratel.persistence.repository.impl.PayorgInfoRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import lombok.NonNull;

/**
 * @Author: hulk
 * @E-mail: 29572320@qq.com
 * @Date: Create in 2018/8/31 下午10:41
 * @Version: 1.0.0
 * @Modify by:
 * Class description
 */
@Slf4j
@Component
public class PayOrgInfoCache {


    @Autowired
    private IPayorgInfoRepository payorgInfoRepository;

    /**
     * 支付机构
     *
     * @param payOrgCode
     * @return
     */

    @Cached( key = "#payOrgCode  + 'PayOrgInfoCache_findPayorgInfo'", cacheType = CacheType.LOCAL ,expire =600 )
    public PayorgInfo findPayorgInfo( @NonNull String payOrgCode) {
        PayorgInfo param = new PayorgInfo();
        param.setOrgCode(payOrgCode);
        param.setArchivedFlag(YesOrNo.NO.getValue());
        param.setAuditedFlag(YesOrNo.YES.getValue());
        param.setStatus(PayOrgStatus.ENABLED.getValue());
        Wrapper<PayorgInfo> query = new QueryWrapper<>(param);
        return payorgInfoRepository.getOne(query);
    }
}
